import { api } from "@/global/utils/api"
import useApiPromiseHandler from "./api-promise-handler"
import { useI18n } from "vue-i18n"
import { message } from 'ant-design-vue';
import 'ant-design-vue/es/message/style/css';

export default function useStaffModifier() {
  const { t } = useI18n();

  const updateStaffAvater = (newAvaterUrl, onSuccess) => {
    useApiPromiseHandler(t, 
      api.post(`/staff/modifyStaffAvater`, {
        url: newAvaterUrl
      }),
      onSuccess,
      (e) => message.error(`出现错误：${e}`)
    )
  };

  const updateStaff = (staff, onModifySuccessed, onModifyFaild) => {
    useApiPromiseHandler(t,
      api.post('/staff/modifyStaff', staff),
      onModifySuccessed, onModifyFaild
    )
  }

  return { updateStaffAvater, updateStaff };
}